import math
from math import degrees, radians

import random
from random import choice

import pyglet
from pyglet.gl import  *
from pyglet.window import key

import cocos
from cocos.actions import *
from cocos.layer import *
from cocos.scene import *
from cocos.director import director
from cocos.scenes.transitions import *
from cocos.sprite import Sprite
from cocos.particle import *
from cocos.particle_systems import *

import Box2D as box2d

from res import Images


class State(object):
    def __init__(self):
        pass     
    def do_actions(self):
        pass
    
    def check_conditions(self):        
        pass    
    
    def entry_actions(self):        
        pass    
    
    def exit_actions(self):        
        pass
        
        
class StateMachine(object):
    
    def __init__(self):
        self.states = {}
        self.active_state = None
    
    
    def add_state(self, state):
        self.states[state.name] = state
        
    def think(self):
        if self.active_state is None:
            return   
        self.active_state.do_actions()        

        new_state_name = self.active_state.check_conditions()
        if new_state_name is not None:
            self.set_state(new_state_name)
        
    def set_state(self, new_state_name): 
        if self.active_state is not None:
            self.active_state.exit_actions()
            
        self.active_state = self.states[new_state_name]        
        self.active_state.entry_actions()
        
      
    